<?php

include_once $_SERVER['DOCUMENT_ROOT'].'/phorm/records/Record.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/phorm/database/xml/XMLCRUD.php';

class XMLRecord extends XMLCRUD
{
	public    $id;
	public    $record;
	
	public function create()
	{
		$this->buildTable();
	}
	
	public function initWithId($id, $query = null)
	{
		$this->id = $id;
		if (empty($query))
			$query = $this->buildSelectQuery();
		
		//echo $query;	
		// Add CRUD
		// mysqli methods here.. from Database (need to write/add that);	
	}
	
	public function save()
	{
		$query = $this->buildSaveQuery();
		//echo $query;
	}
	
	public function delete()
	{
		$query = $this->buildDeleteQuery();
		//echo $query;
	}
	
	// borrow from POG CRUD
	public function getList()
	{
	
	}
	
	public function __set($property, $value)
	{
		if (!$this->record)
			$this->record = new Record();
			
		//if (isset($this->record->$property))
		
		if ($value instanceof MySQLColumn)
			$this->record->$property = $value;			
		else
			$this->record->$property->value = $value;
			//echo $property.": ".$this->record->$property->value;
	}
	
	public function __get($property)
	{	
		if (isset($this->record->$property)) 
		{	
			if ($this->record->$property instanceof ForeignKey)
				return $this->record->$property;
			else
				return $this->record->$property->value;
		}
		else
		{	
			return false;
		}
	}
}
?>
